/*   1:    */ package org.jetbrains.generate.tostring.element;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import org.jetbrains.generate.tostring.psi.PsiAdapter;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */ 
/*  13:    */ public class ElementFactory
/*  14:    */ {
/*  15: 27 */   private static final Logger a = Logger.getInstance("#org.jetbrains.generate.tostring.element.ElementFactory");
/*  16:    */   
/*  17:    */   public static ClassElement newClassElement(PsiClass paramPsiClass)
/*  18:    */   {
/*  19: 39 */     ClassElement localClassElement = new ClassElement();
/*  20:    */     
/*  21:    */ 
/*  22: 42 */     localClassElement.setName(paramPsiClass.getName());
/*  23: 43 */     localClassElement.setQualifiedName(paramPsiClass.getQualifiedName());
/*  24:    */     
/*  25:    */ 
/*  26: 46 */     PsiClass localPsiClass = paramPsiClass.getSuperClass();
/*  27: 47 */     if ((localPsiClass != null) && (!"java.lang.Object".equals(localPsiClass.getQualifiedName()))) {
/*  28: 48 */       localClassElement.setSuperName(localPsiClass.getName());
/*  29:    */     }
/*  30: 52 */     localClassElement.setImplementNames(PsiAdapter.getImplementsClassnames(paramPsiClass));
/*  31:    */     
/*  32:    */ 
/*  33: 55 */     localClassElement.setEnum(paramPsiClass.isEnum());
/*  34: 56 */     localClassElement.setDeprecated(paramPsiClass.isDeprecated());
/*  35: 57 */     localClassElement.setException(PsiAdapter.isExceptionClass(paramPsiClass));
/*  36: 58 */     localClassElement.setAbstract(paramPsiClass.hasModifierProperty("abstract"));
/*  37:    */     
/*  38: 60 */     return localClassElement;
/*  39:    */   }
/*  40:    */   
/*  41:    */   public static FieldElement newFieldElement(PsiField paramPsiField)
/*  42:    */   {
/*  43: 70 */     FieldElement localFieldElement = new FieldElement();
/*  44: 71 */     localFieldElement.setName(paramPsiField.getName());
/*  45: 73 */     if (PsiAdapter.isConstantField(paramPsiField)) {
/*  46: 73 */       localFieldElement.setConstant(true);
/*  47:    */     }
/*  48: 74 */     if (PsiAdapter.isEnumField(paramPsiField)) {
/*  49: 74 */       localFieldElement.setEnum(true);
/*  50:    */     }
/*  51: 75 */     PsiModifierList localPsiModifierList = paramPsiField.getModifierList();
/*  52: 76 */     if (localPsiModifierList != null)
/*  53:    */     {
/*  54: 77 */       if (localPsiModifierList.hasModifierProperty("transient")) {
/*  55: 77 */         localFieldElement.setModifierTransient(true);
/*  56:    */       }
/*  57: 78 */       if (localPsiModifierList.hasModifierProperty("volatile")) {
/*  58: 78 */         localFieldElement.setModifierVolatile(true);
/*  59:    */       }
/*  60:    */     }
/*  61: 81 */     PsiElementFactory localPsiElementFactory = JavaPsiFacade.getInstance(paramPsiField.getProject()).getElementFactory();
/*  62: 82 */     PsiType localPsiType = paramPsiField.getType();
/*  63: 83 */     a(localFieldElement, localPsiElementFactory, localPsiType, localPsiModifierList);
/*  64:    */     
/*  65: 85 */     return localFieldElement;
/*  66:    */   }
/*  67:    */   
/*  68:    */   public static MethodElement newMethodElement(PsiMethod paramPsiMethod)
/*  69:    */   {
/*  70: 96 */     MethodElement localMethodElement = new MethodElement();
/*  71: 97 */     PsiType localPsiType = paramPsiMethod.getReturnType();
/*  72: 98 */     PsiModifierList localPsiModifierList = paramPsiMethod.getModifierList();
/*  73:102 */     if (localPsiType == null)
/*  74:    */     {
/*  75:103 */       a.warn("This method does not have a valid return type: " + paramPsiMethod.getName() + ", returnType=" + localPsiType);
/*  76:104 */       return localMethodElement;
/*  77:    */     }
/*  78:106 */     PsiElementFactory localPsiElementFactory = JavaPsiFacade.getInstance(paramPsiMethod.getProject()).getElementFactory();
/*  79:107 */     a(localMethodElement, localPsiElementFactory, localPsiType, localPsiModifierList);
/*  80:    */     
/*  81:    */ 
/*  82:110 */     String str = PsiAdapter.getGetterFieldName(paramPsiMethod);
/*  83:111 */     localMethodElement.setName(str == null ? paramPsiMethod.getName() : str);
/*  84:112 */     localMethodElement.setFieldName(str);
/*  85:113 */     localMethodElement.setMethodName(paramPsiMethod.getName());
/*  86:    */     
/*  87:    */ 
/*  88:116 */     localMethodElement.setGetter(PsiAdapter.isGetterMethod(paramPsiMethod));
/*  89:    */     
/*  90:    */ 
/*  91:119 */     localMethodElement.setDeprecated(paramPsiMethod.isDeprecated());
/*  92:120 */     localMethodElement.setReturnTypeVoid(PsiAdapter.isTypeOfVoid(paramPsiMethod.getReturnType()));
/*  93:123 */     if (localPsiModifierList.hasModifierProperty("abstract")) {
/*  94:123 */       localMethodElement.setModifierAbstract(true);
/*  95:    */     }
/*  96:124 */     if (localPsiModifierList.hasModifierProperty("synchronized")) {
/*  97:124 */       localMethodElement.setModifierSynchronized(true);
/*  98:    */     }
/*  99:126 */     return localMethodElement;
/* 100:    */   }
/* 101:    */   
/* 102:    */   private static void a(AbstractElement paramAbstractElement, PsiElementFactory paramPsiElementFactory, PsiType paramPsiType, PsiModifierList paramPsiModifierList)
/* 103:    */   {
/* 104:144 */     paramAbstractElement.setTypeName(PsiAdapter.getTypeClassName(paramPsiType));
/* 105:145 */     paramAbstractElement.setTypeQualifiedName(PsiAdapter.getTypeQualifiedClassName(paramPsiType));
/* 106:148 */     if (PsiAdapter.isObjectArrayType(paramPsiType))
/* 107:    */     {
/* 108:149 */       paramAbstractElement.setObjectArray(true);
/* 109:150 */       paramAbstractElement.setArray(true);
/* 110:153 */       if (PsiAdapter.isStringArrayType(paramPsiType)) {
/* 111:153 */         paramAbstractElement.setStringArray(true);
/* 112:    */       }
/* 113:    */     }
/* 114:156 */     else if (PsiAdapter.isPrimitiveArrayType(paramPsiType))
/* 115:    */     {
/* 116:157 */       paramAbstractElement.setPrimitiveArray(true);
/* 117:158 */       paramAbstractElement.setArray(true);
/* 118:    */     }
/* 119:160 */     if (PsiAdapter.isCollectionType(paramPsiElementFactory, paramPsiType)) {
/* 120:160 */       paramAbstractElement.setCollection(true);
/* 121:    */     }
/* 122:161 */     if (PsiAdapter.isListType(paramPsiElementFactory, paramPsiType)) {
/* 123:161 */       paramAbstractElement.setList(true);
/* 124:    */     }
/* 125:162 */     if (PsiAdapter.isSetType(paramPsiElementFactory, paramPsiType)) {
/* 126:162 */       paramAbstractElement.setSet(true);
/* 127:    */     }
/* 128:163 */     if (PsiAdapter.isMapType(paramPsiElementFactory, paramPsiType)) {
/* 129:163 */       paramAbstractElement.setMap(true);
/* 130:    */     }
/* 131:166 */     if (PsiAdapter.isPrimitiveType(paramPsiType)) {
/* 132:166 */       paramAbstractElement.setPrimitive(true);
/* 133:    */     }
/* 134:167 */     if (PsiAdapter.isObjectType(paramPsiElementFactory, paramPsiType)) {
/* 135:167 */       paramAbstractElement.setObject(true);
/* 136:    */     }
/* 137:168 */     if (PsiAdapter.isStringType(paramPsiElementFactory, paramPsiType)) {
/* 138:168 */       paramAbstractElement.setString(true);
/* 139:    */     }
/* 140:169 */     if (PsiAdapter.isNumericType(paramPsiElementFactory, paramPsiType)) {
/* 141:169 */       paramAbstractElement.setNumeric(true);
/* 142:    */     }
/* 143:170 */     if (PsiAdapter.isDateType(paramPsiElementFactory, paramPsiType)) {
/* 144:170 */       paramAbstractElement.setDate(true);
/* 145:    */     }
/* 146:171 */     if (PsiAdapter.isCalendarType(paramPsiElementFactory, paramPsiType)) {
/* 147:171 */       paramAbstractElement.setCalendar(true);
/* 148:    */     }
/* 149:172 */     if (PsiAdapter.isBooleanType(paramPsiElementFactory, paramPsiType)) {
/* 150:172 */       paramAbstractElement.setBoolean(true);
/* 151:    */     }
/* 152:175 */     if (paramPsiModifierList != null)
/* 153:    */     {
/* 154:176 */       if (paramPsiModifierList.hasModifierProperty("static")) {
/* 155:176 */         paramAbstractElement.setModifierStatic(true);
/* 156:    */       }
/* 157:177 */       if (paramPsiModifierList.hasModifierProperty("final")) {
/* 158:177 */         paramAbstractElement.setModifierFinal(true);
/* 159:    */       }
/* 160:178 */       if (paramPsiModifierList.hasModifierProperty("public")) {
/* 161:179 */         paramAbstractElement.setModifierPublic(true);
/* 162:181 */       } else if (paramPsiModifierList.hasModifierProperty("protected")) {
/* 163:182 */         paramAbstractElement.setModifierProtected(true);
/* 164:184 */       } else if (paramPsiModifierList.hasModifierProperty("packageLocal")) {
/* 165:185 */         paramAbstractElement.setModifierPackageLocal(true);
/* 166:187 */       } else if (paramPsiModifierList.hasModifierProperty("private")) {
/* 167:187 */         paramAbstractElement.setModifierPrivate(true);
/* 168:    */       }
/* 169:    */     }
/* 170:    */   }
/* 171:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.generate.tostring.element.ElementFactory

 * JD-Core Version:    0.7.0.1

 */